package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.Tcoursedaohh;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class TcoursedaoImplhh implements Tcoursedaohh{
	//获取当前教师的所有课程
	public JSONArray getcourse(int tid) {
		JSONArray courses=new JSONArray();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT * from course where tid=?");
		Connection  con=JDBCUtil.getConnection();
		try {
			PreparedStatement  pst = con.prepareStatement(sql.toString());
			pst.setInt(1, tid);
			
			ResultSet  rs = pst.executeQuery();
			while (rs.next()) {
				JSONObject  func =  new JSONObject();
				func.put("cid", rs.getInt("cid"));
				func.put("cname", rs.getString("cname"));
				func.put("classtime", rs.getString("classtime"));
				func.put("place", rs.getString("place"));
				courses.add(func);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return courses;
	}
	//通过教师id获取教师的课程在下拉列表
	@Override
	public JSONArray getkc(int tid) {
		JSONArray courses=new JSONArray();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT course.cname,cid from course where tid=?");
		
		Connection  con = JDBCUtil.getConnection();
		try {
			PreparedStatement  pst = con.prepareStatement(sql.toString());
			pst.setInt(1, tid);
			
			ResultSet  rs = pst.executeQuery();
			while (rs.next()) {
				JSONObject  func =  new JSONObject();
				func.put("id", rs.getInt("cid"));
				func.put("text", rs.getString("cname"));
				
				courses.add(func);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		return courses;
	}

	
	

	

}
